package com.foreknow.springboot.mapper;

import com.foreknow.springboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/13 19:38
 * @function:
 */
//   表示当前的Mapper层交给Mybatis来实现
@Mapper
public interface DeliveryAddressMapper {
    /**
     * 根据用户编号查询所属送货地址
     * @param userId
     * @return
     */
    @Select("select * from deliveryaddress where userId=#{userId}")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) ;

    /**
     * 根据送货地址编号查询送货地址
     * @param daId
     * @return
     */
    @Select("SELECT * from deliveryaddress where daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(Integer daId) ;

    /**
     * 向送货地址表中添加一条记录
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     */
    @Insert("insert into deliveryaddress(contactName,contactSex,contactTel,address,userId) values (#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddress(String contactName,Integer contactSex,String contactTel,String address,String userId) ;

    /**
     * 根据送货地址编号更新送货地址信息
     * @param daId
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     */
    @Update("update deliveryaddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address},userId=#{userId} where daId=#{daId}")
    public int updateDeliveryAddress(Integer daId,String contactName,Integer contactSex,String contactTel,String address,String userId) ;

    /**
     * 根据送货地址编号删除一条记录
     * @param daId
     * @return
     */
    @Delete("DELETE from deliveryaddress where daId=#{daId}")
    public int removeDeliveryAddress(Integer daId) ;

}
